<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{'/webjars/layui/2.3.0/css/layui.css'}">
    <link rel="shortcut icon" th:href="@{'/img/favicon.ico'}">
    <link rel="stylesheet" th:href="@{'/webjars/font-awesome/4.7.0/css/font-awesome.css'}">
    <script language="JavaScript" th:src="@{'/webjars/jquery/3.3.1/dist/jquery.min.js'}"></script>
    <script language="JavaScript" th:src="@{'/js/dateformat.js'}" charset="utf-8"></script>
    <script language="JavaScript"
            th:src="@{'/webjars/echarts/3.2.3/echarts.js'}"></script>
    <script language="JavaScript" data-th-src="@{'http://www.xdocin.com/xdoc.js'}"></script>
</head>
<body>
<input type="hidden" th:value="${sid}" id="sidInput">
<ul th:insert="~{fragment/header :: top}"></ul>
<br><br>
<div class="layui-container layui-fluid layui-row">
    <button type="button" class="layui-btn layui-col-lg-offset5" id="test1">
        <i class="layui-icon">&#xe67c;</i>选择学生信息表
    </button>
    <button type="button" class="layui-btn" id="upload">上传
    </button>
</div>
<script language="JavaScript">
    $(function () {
        layui.use(["upload", "layer"], function () {
            var $upload = layui.upload;
            var $layer = layui.layer;

            //执行实例
            var uploadInst = $upload.render({
                //绑定元素
                elem: '#test1',
                //上传接口
                url: '/stu/student/importStu/',
                //设置文件不自动上传
                auto: false,
                //设置上传文件
                accept: "file",
                //绑定一个按钮触发上传
                bindAction: '#upload',
                //选择文件后触发
                choose: function(obj){
                    console.log(obj);
                    obj.preview(function(index, file, result){
                        console.log(result); //得到文件base64编码，比如图片
                        XDoc.run(result, "s.pdf", {}, "_blank");
                    });
                },
                //上传完毕回调
                done: function (res) {
                    console.log(res);
                    if (res.code === 400) {
                        $layer.msg(res.msg, {
                            icon: 5,
                        });
                    }
                    if (res.code === 200)  {
                        window.location.href = "/stu/student/to/stuInfo/get";
                    }
                },
                //请求异常回调
                error: function () {

                }
            });
        });
    });
</script>
<div th:insert="~{fragment/header::footer}"></div>
</body>
<script language="JavaScript" th:src="@{'/webjars/layui/2.3.0/layui.all.js'}" charset="utf-8"></script>
</html>